unit XMLThemes;

interface

uses
  BaseXML, Contnrs;

type

  TSkinTheme = class
  public
    Index: Integer;
    SkinDisplayName,SkinName: string;
  end;

  TXMLThemes = class(TAccessXML)
  private
    FThemes: TObjectList;
    function GetSkinTheme(index: Integer): TSkinTheme;
  protected
    procedure Init; override;
  public
    procedure CreateThemes;
    function Count: Integer;
    function FindByDispName(ADisPlayName: string): TSkinTheme;
    function FindByName(ASkinName: string): TSkinTheme;
    function IndexOf(ASkinTheme: TSkinTheme): Integer;
    property Items[index: Integer]: TSkinTheme read GetSkinTheme; default;
    destructor Destroy; override;
  end;

implementation

{ TAppConfigXML }

destructor TXMLThemes.Destroy;
begin
  FThemes.Free;
  inherited;
end;

function TXMLThemes.FindByDispName(ADisPlayName: string): TSkinTheme;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to FThemes.Count - 1 do
    if (FThemes[I] as TSkinTheme).SkinDisplayName = ADisPlayName then
    begin
      Result := (FThemes[I] as TSkinTheme);
      Break;
    end;
end;

function TXMLThemes.FindByName(ASkinName: string): TSkinTheme;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to FThemes.Count - 1 do
    if (FThemes[I] as TSkinTheme).SkinName = ASkinName then
    begin
      Result := (FThemes[I] as TSkinTheme);
      Break;
    end;
end;

function TXMLThemes.GetSkinTheme(index: Integer): TSkinTheme;
begin
  Result := FThemes[index] as TSkinTheme;
end;

function TXMLThemes.Count: Integer;
begin
  Result := FThemes.Count;
end;

procedure TXMLThemes.CreateThemes;
var
  I: Integer;
  ASkinTheme: TSkinTheme;
begin
  FThemes.Clear;
  with FXMLDocument.Node.ChildNodes.Nodes['dgsoft-app'].ChildNodes.Nodes['themes'] do
  begin
    for I := 0 to ChildNodes.Count - 1 do
    begin
      ASkinTheme := TSkinTheme.Create;
      ASkinTheme.Index := I;
      ASkinTheme.SkinName := TrimVar(ChildNodes.Nodes[I].AttributeNodes.Nodes['name'].NodeValue);
      ASkinTheme.SkinDisplayName := TrimVar(ChildNodes.Nodes[I].NodeValue);
      FThemes.Add(ASkinTheme);
    end;
  end;
end;

function TXMLThemes.IndexOf(ASkinTheme: TSkinTheme): Integer;
begin
  Result := FThemes.IndexOf(ASkinTheme);
end;

procedure TXMLThemes.Init;
begin
  inherited;
  FThemes := TObjectList.Create(True);
end;

end.
